<?php
$session_id=$_REQUEST['sid'];
@session_id($session_id);
@session_start();

$userid=$_SESSION['uid'];
//var_dump($userid);var_dump($session_id);
define('EmpireCMSAdmin','1');
require_once("../class/connect.php");
require_once("../class/db_sql.php");
require_once("../class/functions.php");
require_once("../class/user.php");
require_once("../class/page_obj.php");
define("FILE_PATH",str_replace("\\","/",dirname(dirname(dirname(__FILE__)))).'/');
$link=db_connect();
$empire=new mysqlquery();
$dirPath="album/".date("Y_m_d");
$dir=FILE_PATH.$dirPath;
if($_FILES['Filedata']['size']>1024*1024*2){show_error("请上传2M以内的照片。");}
if($_FILES['Filedata']['error']!=0){show_error("发生系统错误，请与系统管理员联系");}
if(!$userid){show_error("用户未登录，不能添加照片！");}
$info=pathinfo($_FILES['Filedata']['name']);
$extName=strtolower($info['extension']);
$fileName=str_replace(".{$info['extension']}","",$info['basename']);
$md5Str=md5(uniqid(microtime()));
$newName="{$userid}_$md5Str.".$extName;
if(!in_array($extName,array("gif","jpg","png"))){show_error("系统只能支持gif、jpg、png图片！");}
if(!is_dir($dir)){
	@mkdir($dir);
	@chmod($dir,'755');
}else{}
if(move_uploaded_file($_FILES["Filedata"]["tmp_name"],$dir."/".$newName)){
	$db="phome_jat_pic";
	$act_id=$_REQUEST['act_id'];
	$arr=array("uid"=>$userid,"title"=>$fileName,"url"=>$public_r['newsurl'].$dirPath."/".$newName."","shoot_time"=>time(),"time"=>1);	
	$id=DbAdd($db,$arr);
	$arr['id']=$id;
}else{
	show_error("移动文件时，发生系统错误！");
}
die(json_encode($arr));

?>